home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / fontutil.6 / fontutil / fontutils-0.6 / lib / list.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-13  |  1.6 KB  |  65 lines

  1. /* list.c: simple list (represented as arrays) manipulation.
  2.  
  3. Copyright (C) 1992 Free Software Foundation, Inc.
  4.  
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2, or (at your option)
  8. any later version.
  9.  
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  18.  
  19. #include "config.h"
  20.  
  21. #include "list.h"
  22.  
  23.  
  24. list_type
  25. list_init ()
  26. {
  27.   list_type answer;
  28.  
  29.   LIST_DATA (answer) = NULL;
  30.   LIST_SIZE (answer) = 0;
  31.  
  32.   return answer;
  33. }
  34.  
  35.  
  36. /* Free the memory for both the elements and the list itself.  */
  37.  
  38. void
  39. list_free (list_type *list)
  40. {
  41.   if (list != NULL && LIST_DATA (*list) != NULL)
  42.     {
  43.       unsigned e;
  44.       
  45.       for (e = 0; e < LIST_SIZE (*list); e++)
  46.         free (LIST_ELT (*list, e));
  47.       
  48.       free (LIST_DATA (*list));
  49.     }
  50. }
  51.  
  52. /* The list consists entirely of pointers to objects.  We allocate the
  53.    space for the objects pointed to here, though, and return a pointer to
  54.    the newly-created final element in the list.  */
  55.  
  56. address
  57. list_append (list_type *list, unsigned element_size)
  58. {
  59.   LIST_SIZE (*list)++;
  60.   XRETALLOC (LIST_DATA (*list), LIST_SIZE (*list), address);
  61.   LIST_LAST_ELT (*list) = xmalloc (element_size);
  62.  
  63.   return LIST_LAST_ELT (*list);
  64. }
  65.